home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / sound / sndplaydoublebuffer / _headers / dbff.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  12.8 KB  |  343 lines

  1. /*
  2.     File:        DBFF.h
  3.  
  4.     Contains:    Headers for routines called to play a sound from disk using DBFF functions.
  5.  
  6.     Written by: Mark Cookson    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/31/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. /*
  25.     This file contains the function prototypes so that if you built the source
  26.     into a library you would only need this file and DBFF_Errors.h to compile
  27.     your source.  This also provides for some data hiding by typedef'ing the
  28.     SoundInfoPtr into just a Ptr.  This file is not needed if you are not using
  29.     the code to build a library.
  30. */
  31.  
  32. #ifndef __DBFF__
  33. #define __DBFF__
  34.  
  35. #include <Sound.h>
  36. #include "DBFF_Errors.h"
  37.  
  38. #define kFreeMem            1
  39. #define kCloseFile            2
  40.  
  41. typedef Ptr SoundInfoPtr;
  42.  
  43. /* Function definitions */
  44.  
  45. /*    Purpose:        This creates a new SoundInfo structure and initializes
  46.                     it by calling ASoundInit.
  47.     Side Effects:    None.
  48. */
  49. /*-----------------------------------------------------------------------*/
  50. SoundInfoPtr    ASoundNew                (OSErr *theErr);
  51. /*-----------------------------------------------------------------------*/
  52.  
  53. /*
  54.     Purpose:        Display a StandardFile dialog to select an AIFF file.
  55.                     Open the file selected by the user.
  56.     Side Effects:    None.
  57. */
  58. /*-----------------------------------------------------------------------*/
  59. OSErr            ASoundGetFileToPlay        (SoundInfoPtr theSoundInfo);
  60. /*-----------------------------------------------------------------------*/
  61.  
  62. /*
  63.     Purpose:        Checks a file to see if its header can be parsed
  64.                     and the file can be played.
  65.                     
  66.                     This will return an error if the sound will not play,
  67.                     returning noErr means that sound will play.
  68.     Side Effects:    None.
  69. */
  70. /*-----------------------------------------------------------------------*/
  71. OSErr            ASoundCanThisPlay        (CInfoPBPtr theFileInfo);
  72. /*-----------------------------------------------------------------------*/
  73.  
  74. /*
  75.     Purpose:        Wrapper function called to get ready to play a sound.
  76.                     Use this if you want to make sure that there is enough
  77.                     memory to play the sound.
  78.     Side Effects:    This will call routines that will allocate memory needed
  79.                     to all of the various structures needed by the Sound Manager
  80.                     and memory to be used as the sounds' buffers.
  81. */
  82. /*-----------------------------------------------------------------------*/
  83. OSErr            ASoundReadyForPlaying    (SoundInfoPtr theSoundInfo,
  84.                                         unsigned long bufferSize);
  85. /*-----------------------------------------------------------------------*/
  86.  
  87. /*
  88.     Purpose:        Call this after you have called ASoundReadyForPlaying to
  89.                     start playing the sound you prepaired.
  90.     Side Effects:    Starts the sound playing.
  91. */
  92. /*-----------------------------------------------------------------------*/
  93. OSErr            ASoundPlay                (SoundInfoPtr theSoundInfo);
  94. /*-----------------------------------------------------------------------*/
  95.  
  96. /*
  97.     Purpose:        Wrapper function called to start playing a sound.
  98.                     Use this if you are pretty sure the sound will play, or
  99.                     just don't care specifically what goes wrong.
  100.     Side Effects:    This will call routines that will allocate memory needed
  101.                     to all of the various structures needed by the Sound Manager
  102.                     and memory to be used as the sounds' buffers.
  103. */
  104. /*-----------------------------------------------------------------------*/
  105. OSErr            ASoundStartPlaying        (SoundInfoPtr theSoundInfo,
  106.                                         unsigned long bufferSize);
  107. /*-----------------------------------------------------------------------*/
  108.  
  109. /*
  110.     Purpose:        Stops the currently playing sound.
  111.     Side Effects:    Stopping the currently playing sound will cause the
  112.                     sound completion routine to run.
  113. */
  114. /*-----------------------------------------------------------------------*/
  115. OSErr            ASoundStop                (SoundInfoPtr theSoundInfo);
  116. /*-----------------------------------------------------------------------*/
  117.  
  118. /*
  119.     Purpose:        Wrapper so the user doesn't have to keep track of if
  120.                     the sound is playing or not.
  121.     Side Effects:    If resuming a sound and the user had also called
  122.                     ASoundPauseForAdjust this will reinstall the sound
  123.                     completion callback.
  124. */
  125. /*-----------------------------------------------------------------------*/
  126. OSErr            ASoundPause                (SoundInfoPtr theSoundInfo);
  127. /*-----------------------------------------------------------------------*/
  128.  
  129. /*
  130.     Purpose:        If the sound is paused, resume playing.  If the sound is
  131.                     playing, pause playing.
  132.                     This differs from ASoundPause because it actually stops
  133.                     the sound instead of pausing it.  When the sound is
  134.                     paused for adjusting you can reset where the sound will
  135.                     next start playing from without having to play the
  136.                     remainder of the current buffer.  This routine is used
  137.                     for the QuickTime style playing.
  138.     Side Effects:    Removes the callback from the sound channel because
  139.                     otherwise while adjusting the sound the Sound Manager
  140.                     would call our clean up routine.
  141.                     When resuming a sound ASoundStartPlaying will install
  142.                     our callback routine if necessary (if the sound wasn't
  143.                     already paused).
  144. */
  145. /*-----------------------------------------------------------------------*/
  146. OSErr            ASoundPauseForAdjust    (SoundInfoPtr theSoundInfo);
  147. /*-----------------------------------------------------------------------*/
  148.  
  149. /*
  150.     Purpose:        Sound is done playing, dispose of the memory we no
  151.                     longer need.
  152.     Side Effects:    None.
  153. */
  154. /*-----------------------------------------------------------------------*/
  155. OSErr            ASoundDonePlaying        (SoundInfoPtr theSoundInfo,
  156.                                         unsigned long options);
  157. /*-----------------------------------------------------------------------*/
  158.  
  159. /*
  160.     Purpose:        Returns the channel for the sound in case you want to
  161.                     send it specific commands.
  162.     Side Effects:    None.
  163. */
  164. /*-----------------------------------------------------------------------*/
  165. SndChannelPtr    ASoundGetChan            (SoundInfoPtr theSoundInfo);
  166. /*-----------------------------------------------------------------------*/
  167.  
  168. /*
  169.     Purpose:        Returns the name of the file containing the currently
  170.                     playing sound.
  171.     Side Effects:    None.
  172. */
  173. /*-----------------------------------------------------------------------*/
  174. OSErr            ASoundGetSoundName        (SoundInfoPtr theSoundInfo,
  175.                                         Str255 theName);
  176. /*-----------------------------------------------------------------------*/
  177.  
  178. /*
  179.     Purpose:        Gets the number of the current buffer
  180.                     (in the range 1 to ASoundGetNumBuffers()) of the
  181.                     currently playing sound.
  182.     Side Effects:    None.
  183. */
  184. /*-----------------------------------------------------------------------*/
  185. long            ASoundGetCurBuffer        (SoundInfoPtr theSoundInfo);
  186. /*-----------------------------------------------------------------------*/
  187.  
  188. /*
  189.     Purpose:        Sets which buffer should be the next buffer to play
  190.                     from (in the range 1 to ASoundGetNumBuffers())
  191.                     for the currently playing sound.
  192.     Side Effects:    None.
  193. */
  194. /*-----------------------------------------------------------------------*/
  195. OSErr            ASoundSetCurBuffer        (SoundInfoPtr theSoundInfo,
  196.                                         long newValue);
  197. /*-----------------------------------------------------------------------*/
  198.  
  199. /*
  200.     Purpose:        Gets the number of buffers that the currently playing
  201.                     sound will need to play in its entirety.
  202.     Side Effects:    None.
  203. */
  204. /*-----------------------------------------------------------------------*/
  205. long            ASoundGetNumBuffers        (SoundInfoPtr theSoundInfo);
  206. /*-----------------------------------------------------------------------*/
  207.  
  208. /*
  209.     Purpose:        Gets the length (in bytes) of the currently playing
  210.                     sound.  This number does not include any header bytes.
  211.     Side Effects:    None.
  212. */
  213. /*-----------------------------------------------------------------------*/
  214. long            ASoundGetNumTotalBytes    (SoundInfoPtr theSoundInfo);
  215. /*-----------------------------------------------------------------------*/
  216.  
  217. /*
  218.     Purpose:        Gets the number of bytes that will be played by the end
  219.                     of the current buffer of the currently playing sound.
  220.     Side Effects:    None.
  221. */
  222. /*-----------------------------------------------------------------------*/
  223. long            ASoundGetBytesCopied    (SoundInfoPtr theSoundInfo);
  224.  
  225. /*
  226.     Purpose:        Sets the location in the file where the next buffer
  227.                     should be filled from for the currently playing sound.
  228.     Side Effects:    None.
  229. */
  230. /*-----------------------------------------------------------------------*/
  231. OSErr            ASoundSetBytesCopied    (SoundInfoPtr theSoundInfo,
  232.                                         long newValue);
  233. /*-----------------------------------------------------------------------*/
  234.  
  235. /*
  236.     Purpose:        Gets the size of a buffer of the currently playing
  237.                     sound.  Multiply by two to know how much memory is
  238.                     reserved for buffering the currently playing sound.
  239.     Side Effects:    None.
  240. */
  241. /*-----------------------------------------------------------------------*/
  242. long            ASoundGetBufferSize        (SoundInfoPtr theSoundInfo);
  243. /*-----------------------------------------------------------------------*/
  244.  
  245. /*
  246.     Purpose:        Gets the UPP for the function that should be called when
  247.                     the currently playing sound finishes.
  248.     Side Effects:    None.
  249. */
  250. /*-----------------------------------------------------------------------*/
  251. SndCallBackUPP    ASoundGetSoundCallBack    (SoundInfoPtr theSoundInfo);
  252. /*-----------------------------------------------------------------------*/
  253.  
  254. /*
  255.     Purpose:        Sets the function that should be called when the the
  256.                     currently playing sound finishes.
  257.     Side Effects:    None.
  258. */
  259. /*-----------------------------------------------------------------------*/
  260. OSErr            ASoundSetSoundCallBack    (SoundInfoPtr theSoundInfo,
  261.                                         void* newValue);
  262. /*-----------------------------------------------------------------------*/
  263.  
  264. /*
  265.     Purpose:        Says to play the currently playing sound backwards
  266.                     (reverses the sound in the buffer).
  267.     Side Effects:    Takes effect when the next sound buffer gets filled.
  268. */
  269. /*-----------------------------------------------------------------------*/
  270. OSErr            ASoundPlayBackwards        (SoundInfoPtr theSoundInfo,
  271.                                         Boolean newValue);
  272. /*-----------------------------------------------------------------------*/
  273.  
  274. /*
  275.     Purpose:        Returns true if the currently playing sound's buffer
  276.                     is set to be reversed.
  277.     Side Effects:    None.
  278. */
  279. /*-----------------------------------------------------------------------*/
  280. Boolean            ASoundIsBackwards        (SoundInfoPtr theSoundInfo);
  281. /*-----------------------------------------------------------------------*/
  282.  
  283. /*
  284.     Purpose:        Returns true if the sound has finished playing.
  285.     Side Effects:    None.
  286. */
  287. /*-----------------------------------------------------------------------*/
  288. Boolean            ASoundIsDone            (SoundInfoPtr theSoundInfo);
  289. /*-----------------------------------------------------------------------*/
  290.  
  291. /*
  292.     Purpose:        Changes the volume of the currently playing sound.
  293.                     The values you pass in are added to the current values.
  294.                     Negitive values will decrease the volume, positive values
  295.                     will increase the volume.
  296.     Side Effects:    None.
  297. */
  298. /*-----------------------------------------------------------------------*/
  299. OSErr            ASoundChangeVolume        (SoundInfoPtr theSoundInfo,
  300.                                         unsigned short leftVol,
  301.                                         unsigned short rightVol);
  302. /*-----------------------------------------------------------------------*/
  303.  
  304. /*
  305.     Purpose:        Gets the volume of the currently playing sound.
  306.     Side Effects:    None.
  307. */
  308. /*-----------------------------------------------------------------------*/
  309. OSErr            ASoundGetVolume            (SoundInfoPtr theSoundInfo,
  310.                                         unsigned short *leftVol,
  311.                                         unsigned short *rightVol);
  312. /*-----------------------------------------------------------------------*/
  313.  
  314. /*
  315.     Purpose:        Sets the volume of the currently playing sound.
  316.     Side Effects:    None.
  317. */
  318. /*-----------------------------------------------------------------------*/
  319. OSErr            ASoundSetVolume            (SoundInfoPtr theSoundInfo,
  320.                                         unsigned short leftVol,
  321.                                         unsigned short rightVol);
  322. /*-----------------------------------------------------------------------*/
  323.  
  324. /*
  325.     Purpose:        Gets the rate multiplier of the currently playing sound.
  326.     Side Effects:    None.
  327. */
  328. /*-----------------------------------------------------------------------*/
  329. OSErr            ASoundGetRateMul        (SoundInfoPtr theSoundInfo,
  330.                                         UnsignedFixed *theRateMul);
  331. /*-----------------------------------------------------------------------*/
  332.  
  333. /*
  334.     Purpose:        Gets the rate multiplier of the currently playing sound.
  335.     Side Effects:    None.
  336. */
  337. /*-----------------------------------------------------------------------*/
  338. OSErr            ASoundSetRateMul        (SoundInfoPtr theSoundInfo,
  339.                                         UnsignedFixed theRateMul);
  340. /*-----------------------------------------------------------------------*/
  341.  
  342. #endif
  343.